clear
use 20221222maindata.dta
xtset code year

//table 2
summarize absinvestment cf3 contest3 tq fcf age  cs rbcs growth leverage lnassets state, detail

// ±í3
pwcorr absinvestment cf3 contest3 tq fcf age  cs rbcs growth leverage lnassets state,sig


global xx "tq fcf age cs rbcs growth leverage lnassets state"


// main test
// table 3

xtreg absinvestment cf3 i.idu i.year,fe
estimates store f1

xtreg absinvestment contest3 i.idu i.year,fe
estimates store f2

xtreg absinvestment cf3 $xx i.idu i.year,fe
estimates store f3

xtreg absinvestment contest3 $xx i.idu i.year,fe
estimates store f4


esttab f1 f2 f3 f4 using 3.rtf, replace nogap compress ///
 r2(%9.3f)  b(%9.3f) t(%9.3f)  ///
 noomit nobase drop (*.year *.idu) star(* 0.1 ** 0.05 *** 0.01 )


//psm
// table 4
set seed 10101
gen ranorder=runiform()
sort ranorder
psmatch2 nclssdummy lnassets leverage tq age i.idu i.year, outcome(absinvestment) n(1) ate ties logit common noreplacement //ÎÞ·Å»Ø
xtset code year
est store p1

drop if _nn==0
drop if _nn==.

reg absinvestment cf3 $xx i.idu i.year
estimates store d1

reg absinvestment contest3 $xx i.idu i.year
estimates store d2

esttab d1 d2  using 4.rtf, replace nogap compress ///
 r2(%9.3f)  b(%9.3f) t(%9.3f)  ///
 noomit nobase  star(* 0.1 ** 0.05 *** 0.01 )

// IV

// table 5
clear
use 20221222maindata.dta
xtset code year

xtivreg absinvestment $xx (cf3=iv),fe first
est store  d1
xtivreg absinvestment $xx (contest3=iv),fe first
est store  d2


esttab d1 d2  using 5.rtf, replace nogap compress ///
 r2(%9.3f)  b(%9.3f) t(%9.3f)  ///
 noomit nobase  star(* 0.1 ** 0.05 *** 0.01 )



clear
// table 6
// cut 10%


_pctile absinvestment,p(10)

return list

drop if absinvestment<=.3554247468709946

xtreg absinvestment cf3 $xx i.idu i.year,fe
est store  d1

xtreg absinvestment contest3 $xx i.idu i.year,fe
est store  d2


esttab d1 d2  using 6-1.rtf, replace nogap compress ///
 r2(%9.3f)  b(%9.3f) t(%9.3f)  ///
 noomit nobase drop (*.year *.idu) star(* 0.1 ** 0.05 *** 0.01 )

// variable separationbstitution
clear
use 20221222maindata.dta
xtset code year

xtreg absinvestment nclssdummy $xx i.idu i.year,fe
est store  d3

xtreg absinvestment cf2 $xx i.idu i.year,fe
est store  d4

xtreg absinvestment contest2 $xx i.idu i.year,fe
est store  d5

esttab  d3 d4 d5 using 6-2.rtf, replace nogap compress ///
 r2(%9.3f)  b(%9.3f) t(%9.3f)  ///
 noomit nobase drop (*.year *.idu) star(* 0.1 ** 0.05 *** 0.01 )


// diffreent regression
// table 7
reg absinvestment cf3 $xx i.idu i.year,r
est store  d1

reg absinvestment contest3 $xx i.idu i.year,r
est store  cf2

xtreg absinvestment cf3 $xx i.idu i.year,re
est store  d3

xtreg absinvestment contest3 $xx i.idu i.year,re
est store  d4


tobit absinvestment cf3 $xx i.idu i.year,ll (0) nolog
est store  d5

tobit absinvestment contest3 $xx i.idu i.year,ll (0) nolog 
est store  d6


reg absinvestment cf3 $xx i.idu i.year
predict r,resid
gen logusq=ln(r^2)
reg logusq cf3 $xx i.idu i.year
predict g,xb
gen h=exp(g)
reg absinvestment cf3 $xx i.idu i.year [aweight=h]
est store  d7
esttab d3 using 4.doc, replace r2(%9.4f) ar2(%9.4f) b(%9.4f)t(%9.4f) 

reg absinvestment contest3 $xx i.idu i.year
predict r1,resid
gen logusq1=ln(r1^2)
reg logusq1 contest3 $xx i.idu i.year
predict g1,xb
gen h6=exp(g1)
reg absinvestment contest3 $xx i.idu i.year [aweight=h6]
est store  d8

esttab d1 cf2 d3 d4 d5 d6 d7 d8 using 7.rtf, replace nogap compress ///
 r2(%9.3f)  b(%9.3f) t(%9.3f)  ///
 noomit nobase drop (*.year *.idu) star(* 0.1 ** 0.05 *** 0.01 )

//threshold models
// table 8
clear
use 20221222maindata.dta
xtset code year

xthreg absinvestment tq fcf age rbcs growth leverage lnassets state, rx(cf3) qx(cs) thnum(2) grid(400) trim(0.01 0.05) bs (300 300)
est store  d1
xthreg absinvestment tq fcf age cs growth leverage lnassets state, rx(cf3) qx(rbcs) thnum(2) grid(400) trim(0.01 0.05) bs (300 300)
est store  d2

xthreg absinvestment tq fcf age rbcs growth leverage lnassets state, rx(contest3) qx(cs) thnum(1) grid(400) trim(0.01) bs (300)
est store  d3
xthreg absinvestment tq fcf age cs growth leverage lnassets state, rx(contest3) qx(rbcs) thnum(2) grid(400) trim(0.01 0.05) bs (300 300)
est store  d4
xthreg absinvestment tq fcf age cs rbcs growth leverage lnassets state, rx(cf3) qx(separation) thnum(1) grid(400) trim(0.01) bs (300)
est store  d5

esttab d1 d2 d3 d4 d5 using 8.rtf, replace nogap compress ///
 r2(%9.3f)  b(%9.3f) t(%9.3f)  ///
 noomit nobase star(* 0.1 ** 0.05 *** 0.01 )





//nature feture state=1 vs state=0
clear
// table 9
xtreg absinvestment cf3 $xx i.idu i.year if state==1,fe 
est store  d1

xtreg absinvestment contest3 $xx i.idu i.year if state==1,fe 
est store  d2

xtreg absinvestment cf3 $xx i.idu i.year if state==0,fe 
est store  d3

xtreg absinvestment contest3 $xx i.idu i.year if state==0,fe 
est store  d4

esttab d1 d2 d3 d4 using 9.rtf, replace nogap compress ///
 r2(%9.3f)  b(%9.3f) t(%9.3f)  ///
 noomit nobase drop (*.year *.idu) star(* 0.1 ** 0.05 *** 0.01 )


 

clear
// overinvestment vs underinvestment
// table 10
clear
use 20221222maindata.dta
xtset code year
drop if overinvestment==0

xtreg overinvestment cf3 $xx i.idu i.year,fe 
est store  d1

xtreg overinvestment contest3 $xx i.idu i.year,fe 
est store  d2

esttab d1 d2 using 10-1.rtf, replace nogap compress ///
 r2(%9.3f)  b(%9.3f) t(%9.3f)  ///
 noomit nobase drop (*.year *.idu) star(* 0.1 ** 0.05 *** 0.01 )

clear
use 20221222maindata.dta
xtset code year
drop if underinvestment==0

xtreg underinvestment cf3 $xx i.idu i.year,fe 
est store  d3

xtreg underinvestment contest3 $xx i.idu i.year,fe 
est store  d4

esttab d3 d4 using 10-2.rtf, replace nogap compress ///
 r2(%9.3f)  b(%9.3f) t(%9.3f)  ///
 noomit nobase drop (*.year *.idu) star(* 0.1 ** 0.05 *** 0.01 )
